import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_deer/order/widgets/pay_type_dialog.dart';
import 'package:flutter_deer/index/index_router.dart';
import 'package:flutter_deer/res/resources.dart';
import 'package:flutter_deer/routers/fluro_navigator.dart';
import 'package:flutter_deer/util/other_utils.dart';
import 'package:flutter_deer/util/theme_utils.dart';
import 'package:flutter_deer/util/toast_utils.dart';
import 'package:flutter_deer/widgets/my_card.dart';
import 'package:flutter_deer/util/image_utils.dart';
import 'package:flutter_deer/widgets/load_image.dart';
import 'package:flutter_deer/index/models/play_entity.dart';

class PlayItem extends StatelessWidget {

  const PlayItem({
    super.key,
    required this.tabIndex,
    required this.index,
  });

  final int tabIndex;
  final int index;
  
  @override
  Widget build(BuildContext context) {

    return Padding(
      padding: const EdgeInsets.only(top: 8.0),
      child: MyCard(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: InkWell(
            onTap: () => NavigatorUtils.push(context, IndexRouter.indexDetailPage),
            child: _buildContent(context),
          ),
        ),
      )
    );
  }

  Widget _buildContent(BuildContext context) {
    List<PlayItems> playItemList = <PlayItems>[];
    playItemList.insert(0,PlayItems(id:1,name:'国际赛21岁以下',footballTeamOneName:'捷克',footballTeamOneImage:'http://47.122.45.246/admin/sys-file/science/baa1ff762aa34461be84ba5fba1605c6.png',footballTeamTwoName:'德国',footballTeamTwoImage:'http://47.122.45.246/admin/sys-file/science/90b3b1d484524156b9ed2d1a399bd987.png',playTime:'11-22 15:00:00'));
    final TextStyle? textTextStyle = Theme.of(context).textTheme.bodyMedium?.copyWith(fontSize: Dimens.font_sp12);
    final bool isDark = context.isDark;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Row(
          children: <Widget>[
            const Expanded(
              child: Row(
                children: <Widget>[
                  LoadAssetImage('logo',format:ImageFormat.gif,width:30,height:30),
                  Text('国际赛21岁以下')
                ]
              )
            ),
            Text(
              '11-22 15:00:00',
              style: TextStyle(
                fontSize: Dimens.font_sp12,
                color: Theme.of(context).colorScheme.error,
              ),
            ),
          ],
        ),
        Gaps.vGap8,
        Gaps.line,
        Gaps.vGap8,
        DecoratedBox(
            decoration: BoxDecoration(
              // color: isDark ? Colours.dark_bg_color : null,
              gradient: LinearGradient(
                begin: Alignment.topCenter,//渐变开始于上面的中间开始
                end: Alignment.bottomCenter,//渐
                colors: [Colours.gradient_blue, Color(0xFF4647FA)]
              )
            ),
            child: Padding(
              padding: const EdgeInsets.symmetric(horizontal: 0.0),
              child: MyCard(
                color: Colors.transparent,
                child: Container(
                  height: 100.0,
                  padding: const EdgeInsets.only(top: 0.0,left:10,right:10),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          LoadImage('http://47.122.45.246/admin/sys-file/science/baa1ff762aa34461be84ba5fba1605c6.png',width:40,height: 40),
                          SizedBox(width: 12),
                          Text("捷克",style: textTextStyle)
                        ]
                      ),
                      LoadAssetImage('vs',format:ImageFormat.png,width:50,height:50),
                      Row(
                        children: <Widget>[
                          LoadImage('http://47.122.45.246/admin/sys-file/science/90b3b1d484524156b9ed2d1a399bd987.png',width:40,height: 40),
                          SizedBox(width: 12),
                          Text("德国",style: textTextStyle)
                        ]
                      )
                    ]
                  )
                )
              )
            )
        ),
        Gaps.vGap8,
        Gaps.line,
      ],
    );
  }

  void _showPayTypeDialog(BuildContext context) {
    showDialog<void>(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return PayTypeDialog(
          onPressed: (index, type) {
            Toast.show('收款类型：$type');
          },
        );
      },
    );
  }

}


class PlayItemButton extends StatelessWidget {
  
  const PlayItemButton({
    super.key,
    this.bgColor,
    this.textColor,
    required this.text,
    this.onTap
  });
  
  final Color? bgColor;
  final Color? textColor;
  final GestureTapCallback? onTap;
  final String text;
  
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        alignment: Alignment.center,
        padding: const EdgeInsets.symmetric(horizontal: 14.0),
        decoration: BoxDecoration(
          color: bgColor,
          borderRadius: BorderRadius.circular(4.0),
        ),
        constraints: const BoxConstraints(
          minWidth: 64.0,
          maxHeight: 30.0,
          minHeight: 30.0,
        ),
        child: Text(text, style: TextStyle(fontSize: Dimens.font_sp14, color: textColor),),
      ),
    );
  }
}
